Learning precedence for mod rewrite - redirect

I want to redirect some old links to new locations. I am using wordpress.
I added these lines to the top of my .htaccess files because I want URLs of the format
authors/NNNNN/WORDS-GO_HERE to map to /?author=NNNN
articles/NNNN/WORDS-GO_HERE to map to /?p=NNNN
The second one works fine, but the author one does not. If I type the querystring in my browser it finds the authors, but if I try www.myurl.com/authors/NNNNN/blah I get a not found.
Finally, when there was an article with the title Authors should Publish, the URLs that were looking for authors would redirect to that article. I renamed the article and reset its slug, and now I get the not found error.
Any ideas? I would like to become a master of rewrite, but I am not off to a good start.
Cheers
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^authors/([0-9]+)/(.*)$ /?author=$1 [N]
RewriteRule ^articles/([0-9]+)/(.*)$ /?p=$1 [N]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Related

Prestashop language redirection not working

As I understand when adding multiple languages the root URL should automatically redirect to the browser's language, or the default language.
http://example.com should redirect to http://example.com/fr/ for French for example.
On localhost it works, there is a 301 (or 302) returned
. But when I try it prod http://example.com returns an HTTP 200 with a blank page.
I activated friendly URLs, regenerated htaccess file, tried to have only one language activated. Nothing.
Is there something I'm missing? I'm seeing a lot of questions about how NOT to do this redirection.
# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
RewriteEngine on
#Domain: mydomain.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Images
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/font-woff .woff
AddType font/woff2 .woff2
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
In case of a single language on the store, the ISO code is not added to the URL. For example, If you only have English on your PrestaShop store then the front URL will be:
http://example.com/
and not
http://example.com/en/
When you add another language then the ISO code is added to the URL based on the language you have selected on the front end.
Hope this helps.

Deploying Laravel to Bluehost

I was wondering if anyone has had any experience deploying larval to blue host? I was flowing an youtube tutorial that showed how to deploy a larval application to a shared hosting service. It was using Godaddy.com, however, i was using Bluehost, and it didn't work as expected. However I managed to getting to not return an internal server error.
What I did was to configure the .env file so that it had my correct database information and my APP_URL to point to my domain.
The youtube tutorial said I should also remove everything from the public folder and place it in the applications main folder, which on Bluehost is the public_html folder. I also changed the .htaccess and removed the public in the rewrite that handles the redirects for trailing slashed.
Now, when I point to my website, all that is served up is a blank screen. but something seems to be working because I uploaded an html webpage that renders to the browser. I just wondering where do I go from here to get the entire site running.
i'm using php 5.6.
Any help would be great. Thank you
I think you are using shared hosting
Follow these steps
1: After upload files to public_html move all your /public files in public_html folder All files like index.php, .htaccess and assets folder etc
2: Find the following line in index.php
require __DIR__.’/../bootstrap/autoload.php’;
require __DIR__.’/../project/bootstrap/autoload.php’;
change to
require __DIR__.’/bootstrap/autoload.php’;
require __DIR__.’/project/bootstrap/autoload.php’;
That’s it. Well then, have fun.
check that the PHP version is correct for Laravel
in cPanle enable FastCGI for PHP
open file .htaccess located in /public and edit
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteBase /public/
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
This is my .htaccess codes which are different in different server.
#Default Setup
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
//bluehost------------
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Disable mod_rewrite on index

This is my mod_rewrite code:
Options +FollowSymlinks
RewriteEngine on
# ————————————————————————-
# > URL REWRITING
# ————————————————————————-
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)/diario$ hotsite/diary.php
RewriteRule ^(.*)/recados$ hotsite/messages.php
RewriteRule ^(.*)/fotos$ hotsite/photos.php
RewriteRule ^(.*)/videos$ hotsite/videos.php
RewriteRule ^(.*)/contato$ hotsite/contact.php
RewriteRule ^([a-z0-9._\-]+)$ hotsite/index.php [L]
It works just like facebook profiles. Whenever I type "mywebsite.com/user.name" it goes to that user page. I can also type "mywebsite.com/user.name/videos" to go to a specific page in the user profile.
However, I can't access "mywebsite.com" anymore, because it redirects to "mywebsite.com/hotsite/index.php". How can I disable this behavior and leave the redirects only when someone types a user name at the end?
Thank you very much.
The RewriteCondition(s) only affect the RewriteRule that comes immediately after that. So, to stop redirecting htp://mywebsite.com/aDirThatExists like http://mywebsite.com/aboutUs you need to repeat the rewrite conditions as
RewriteCond %{SCRIPT_FILENAME} !-d # if not a directory
RewriteCond %{SCRIPT_FILENAME} !-f # and not a file
RewriteRule ^([a-z0-9._\-]+)$ hotsite/index.php [L]
This, however, should not affect a root URL request i.e. http://mywebsite.com/ because your regex clearly matches one or more characters after / because of the []+ plus sign.

301 Redirecting Dirty URLs to Clean Ones

I really need some help redirecting dirty URLs to clean ones.
Dirty URL: creature.php?beast=
Clean URL: /mythical-creature/
Currently my .htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mythicalcreatureslist.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^www.mythbeasts.com [NC]
RewriteRule ^(.*)$ http://www.mythicalcreatureslist.com/$1 [L,R=301]
RewriteRule ^menu/([A-Za-z0-9-+]+)/?$ menu.php?menu=$1 [NC,L]
RewriteRule ^menu_two/([A-Za-z0-9-+]+)/?$ menu_two.php?menu=$1 [NC,L]
RewriteRule ^mythical-creature/([A-Za-z0-9-+\'%]+)/?$ creature.php?beast=$1 [NC,L]
What this does is it makes the website show clean URLs when browsing which is great. However the old dirty URLs do not redirect when typed in the URL bar.
Example: Mongolian Death Worm
http://www.mythicalcreatureslist.com/creature.php?beast=Mongolian+Death+Worm
I want it to redirect to:
http://www.mythicalcreatureslist.com/mythical-creature/Mongolian+Death+Worm
This is causing duplicate content. I have tried:
RewriteRule ^/mythical-creature/([A-Za-z0-9-+\'%]+)/?$ http://www.mythicalcreatureslist.com/creature.php?beast=$1 [R=301,NC,L]
But what that did was to cause the dirty one to be used all the time.
I then flipped it round:
RewriteRule ^creature.php?beast=([A-Za-z0-9-+\'%]+)/?$ http://www.mythicalcreatureslist.com/mythical-creature/$1 [R=301,NC,L]
But that just caused 404s whilst browsing and still did not redirect the old dirty URLs when typed in the address bar.
The regex did not not match an empty query parameter value. Flip the + to a *
RewriteRule ^/creature.php?beast=([A-Za-z0-9-+\'%]*)/?$ http:// www.mythicalcreatureslist.com/mythical-creature/$1 [R=301,NC,L]
Notice the addition of a leading slash also

400 Bad Request With CSS .htaccess rule

I'm trying to whitelabel the Zend framework, so I've created folder in application called Site.
This url: http://local.branch.test.com/site-css/1/layout.css returns a 400 Bad Request.
With the following rule:
RewriteRule ^site-css/([0-9]+)/(.*)$ ../application/site/$1/design/css/$2 [L]
Full .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
RewriteRule ^site-css/([0-9]+)/(.*)$ ../application/site/$1/design/css/$2 [L]
Ideas?
Try
RewriteBase /
RewriteRule ^site-css/([0-9]+)/(.*)$ ../application/site/$1/design/css/$2 [L]
This is caused by apache being set up to point to /public. The project doesn't have access to read files outside of its root.
Therefore I have moved site into public.