I'm writing an htaccess for handeling my links for seo friendly links. But now suddenly it says an 500 Internal Server Error?? Is there a limit on lines for htaccess?
.htaccess:
ErrorDocument 404 /404/404.html
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteRule ^choose/[a-zA-Z0-9]+)/?$ choose.php?gebruikersnaam=$1 [L,QSA,NC]
blabla, some stuff you don't need to see anymore.
There is a few ways to debug why your .htaccess is not working, the fastest one is if you have access to the web server config file so you can turn on RewriteLog which will pinpoint where it fails for you:
RewriteLog "/path_to_save_it/rewrite_log"
RewriteLogLevel 9
Another way would be by placing your rules inside IfModule directive:
<IfModule mod_rewrite.c>
# your rule comes here
</IfModule>
For example:
Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
ErrorDocument 404 /404/404.html
# Turn mod_rewrite on
RewriteEngine On
RewriteRule ^show/([0-9]+)/?$ show.php?photo=$1 [L,QSA,NC]
RewriteRule ^report/([0-9]+)/?$ report.php?photo=$1 [L,QSA,NC]
RewriteRule ^index/?$ index.php [L,QSA,NC]
RewriteRule ^album/?$ album.php [L,QSA,NC]
RewriteRule ^choose/?$ choose.php [L,QSA,NC]
RewriteRule ^choose/[a-zA-Z0-9]+)/?$ choose.php?gebruikersnaam=$1 [L,QSA,NC]
RewriteRule ^rules/?$ rules.php [L,QSA,NC]
RewriteRule ^winners/?$ winners.php [L,QSA,NC]
RewriteRule ^contact/?$ contact.php [L,QSA,NC]
RewriteRule ^forget-password/?$ password.php [L,QSA,NC]
RewriteRule ^forget-password/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ password.php?gebruiker=$1&wachtwoord=$2 [L,QSA,NC]
RewriteRule ^upload-picture/?$ upload.php [L,QSA,NC]
RewriteRule ^user-cp/?$ user-photo.php [L,QSA,NC]
RewriteRule ^user-cp/delete/([0-9]+)/?$ user-photo.php?delete=$1 [L,QSA,NC]
RewriteRule ^user-cp/yes/([0-9]+)/?$ user-photo.php?yes=$1 [L,QSA,NC]
RewriteRule ^logout/?$ logout.php [L,QSA,NC]
RewriteRule ^mail-second/?$ mail_second.php [L,QSA,NC]
RewriteRule ^activate/?$ activate.php [L,QSA,NC]
RewriteRule ^activate/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ activate.php?code=$1&gebruikersnaam=$2 [L,QSA,NC]
</IfModule>
If all your rules have no issue but mod_rewrite is not enabled you will get no errors so you will know mod_rewrite is not enable if you try any rules.
If you still get error then it means mod_rewrite is enable and 1 or more rules are right, like missing something perhaps.
However from the above you will only know you have a problem, by using the elimination method you will find the exact line or lines that are causing the issue, which is by commenting all lines and then uncomment one by one, testing what that line is supposed to do before moving to the next line.
This way you will pinpoint where the problem is.
Related
I want to make my website temporarily accessible only at example.com/unfinished-version.
All URLs like /style/main.css or /public/style/main.css would point to /soon.html, then all URLs like /unfinished-version/style/main.css would point to URLs like /public/style/main.css.
The rule I wrote doesn't work, because /public/style/main.css or /public/some-page still works.
RewriteRule ^(?!unfinished-version).*$ soon.html [L,NC]
URLs like example.com/gibberish show soon.html, so it does partly work.
I'll show you full .htaccess, although I find it unnecessary. (The rules shouldn't interfere with this, plus the L flag should avoid processing of any further rules in the first place.)
.htaccess in the root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(?!unfinished-version).*$ soon.html [L,NC]
RewriteRule ^unfinished-version(.*)$ public/$1 [L,NC]
</IfModule>
.htaccess in public/:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
</IfModule>
P.S.: Not even RewriteRule ^(.*)$ soon.html [L,NC] works.
I know this is probably a very simple question but I do not manage it to get it working.
I have a joomla application with the following url: http://www.nmo-online.com/news/final and I would like to point it to http://www.nmo-online.com/client/frontend/app/final but with keeping the first url.
So I put a .htaccess file on my server situated in the root folder with the following content:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .*nmo-online.com$
RewriteRule ^news/final client/frontend/app/final [L]
The redirection seems to work but I always get redirected to the homepage, which is http://www.nmo-online.com/weather.
Any help is very appreciated.
enne
Edit: Here is the complete htaccess-file
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .*nmo-online.com$
RewriteRule ^$ client/frontend/questionnaire/index.php [L]
RewriteRule ^weather client/frontend/app/weather [L]
RewriteRule ^news/final client/frontend/app/final [L]
RewriteRule ^flight/search-flight client/frontend/app/search-flight [L]
#Joomla backend
RewriteRule ^administrator client/frontend/app/administrator/ [L]
#Questionnaire backend
RewriteRule ^backend client/backend/index.php [L]
I m sure that many people will say that this is duplicated but I try everything from other "Question"`s and nothings work for me.
The problem is that I move my project to the web server.
In this server I have folder "public_html" where I but my project Symfony.
Now to enter on my project I must write the following url: www.mydomain.com/Symfony/web/*
But I want to write a Rewrite Rule which will redirect from www.mydomain.com/Symfony/web/* to
www.mydomain.com/home/*.
To do this I try on 2 different ways with many combination of ReWrite rule.
In my public_html I create a .htaccess folder
I edit the .htaccess in Symfony/web folder
I add the following rule in both file but without success
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Symfony/web/(.*)$ www.mydomain.com/home/$1 [L,R=301]
Unfortunately without success. What I`m doing wrong?
My htaccess file look like
And all the time Error 404 Object not found
Symfony/web/.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteRule ^home/(.*)$ $1 [L,NC]
</IfModule>
It`s redirecting me but I receive again Object not found :(
I delete the .htaccess in public_html folder which is the root one for my server
public_html\.htaccess
RewriteEngine On
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
1: Place this code in /Symfony/web/.htaccess:
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [L]
2: Place this code in /public_html/.htaccess:
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
I'm going to go out on a limb and say that your rule is backwards. I think you want your URL to be www.mydomain.com/home/* in the browser... In which case the rule would be reversed. Also, your .htaccess should be in the root and you don't need to include the domain in the rewrite rule because you set a rewrite base.
RewriteRule ^home/(.*)$ Symfony/web/$1 [L,R=301]
I have several urls on a Joomla site which have been indexed and I need to 301 redirect them into some new pages. The old URL is formed like this:
http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=20
I want it to go to:
http://www.mydomain.com/en/family-members/family-disease
I tried using:
RewriteCond %{QUERY_STRING} ^start=(.*)$
RewriteRule ^/en/wfmenuconfig/family/family-disease/177-category-english$ http://www.www.mydoamin.com/en/family-members/family-disease%1 [R=301,L]
I've tried several answers on here but nothing seems to be working.
htaccess 301 redirect dynamic url
and
301 Redirecting URLs based on GET variables in .htaccess
Any ideas what I should try next? (I've tried a normal redirect 301)
You've almost got it. You need to remove the leading slash from your rule's pattern because it's removed from the URI when applying rules from an htaccess file:
RewriteCond %{QUERY_STRING} ^start=(.*)$
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english$ /en/family-members/family-disease%1? [R=301,L]
You also don't need the http://www.www.mydoamin.com bit (2 sets of www). At the end of your target, you have family-disease%1, which means if start=20 then the end of your URL will look like: family-disease20. Is that right?
The new URL doesn't have the query string in it, so it is just stripping of the last URL path part. If you want it hardcoded
RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english$ /en/family-members/family-disease? [R,L]
or a little bit more flexible
RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/family/family-disease/.+$ /en/family-members/family-disease? [R,L]
or if you just want to keep two levels after en/wfmenuconfig
RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/(.+?/.+?)/ /en/$1? [R,L]
Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.
If you just want to redirect http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$var into http://www.mydomain.com/en/family-members/family-disease, then you must try these directives:
# once per .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english /en/family-members/family-disease [R=301,L]
But if that's not what you want, but to redirect http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$var into http://www.mydomain.com/en/family-members/family-disease$var then you could check this one:
# once per .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english /en/family-members/family-disease%1 [R=301,L]
Now, give this one a little more try if it will work. If it's not, then find any suspicious why this code is not working:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /en/
RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^wfmenuconfig/family/family-disease/177-category-english /family-members/family-disease [R]
And go to http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$AnyNumber if it's redirecting into http://www.mydomain.com/en/family-members/family-disease just make sure that your web server have mod_rewrite.
I just wanted to throw this out there, I was also having trouble getting the RewriteRule to work. I have a client that upgraded to a WordPress powered site from .asp pages. What I had to do to get this to work is insert the RewriteCond and RewriteRule in the htaccess file BEFORE the "# BEGIN WordPress" section. Now it works just as it should.
This is posted way late, but hopefully it helps someone else out there running into the same issue.
Doesn't Work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{QUERY_STRING} ^var=somestring$ [NC]
RewriteRule ^oldpage\.asp$ http://www.domain.com/newpage? [R=301,L]
Does Work:
RewriteCond %{QUERY_STRING} ^var=somestring$ [NC]
RewriteRule ^oldpage\.asp$ http://www.domain.com/newpage? [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Order of operations must be important =)
I have a URL on my site that works without a / but when I add a / it says there's a redirect loop... I'm struggling to see the problem here....
Options -indexes
RewriteEngine On
#
#
#php_value output_handler ob_gzhandler
php_value output_handler none
php_flag register_globals off
php_flag safe_mode off
ErrorDocument 404 /404
#
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
#
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
RewriteRule ^battery/([^/]+)$ /browser/product?sku=BATTERY+$1&type=battery
RewriteRule ^vehicles/([^/]+)/([^/]+)/([^/]+)/product([0-9]+)$ /browser/index.php?make=$1&model=$2&id=$3&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)/([^/]+)/([^/]+)/([0-9]+)$ /browser/product.php?make=$1&model=$2&year=$3&id=$4&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)/([^/]+)/([^/]+)$ /store/product/list.php?make=$1&model=$2&year=$3&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)/([^/]+)$ /vehicle/make/model/year/list.php?make=$1&model=$2&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)$ /vehicle/make/model/list.php?make=$1&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/$ /vehicle/make/list.php{QUERY_STRING} [L,NC]
RewriteRule ^keyfinder /browser/product?id=1001552 [L,NC]
I probably would have done some of the regular expression different for the RewriteRule, but it seems to be working accept for that trailing slash. Add /? to the end of each one of your RewriteRules for vehicles, battery & keyfinder. The /? is saying to look for zero or one trailing slash at the end of the line.
Here is an example:
RewriteRule ^vehicles/([^/]+)/([^/]+)/?$ /vehicle/make/model/year/list.php?make=$1&model=$2&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+/?)$ /vehicle/make/model/list.php?make=$1&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/?$ /vehicle/make/list.php{QUERY_STRING} [L,NC]
The changes above will solve the problem of the redirecting loop caused by the trailing slash, but not the redirecting loop itself. You might have expected your 404 page to show up instead. It didn't work because "ErrorDocument" is wrong. There is no extension for the 404 page.
So again as an example, if your error page is called 404.php, the line needs to look like this...
ErrorDocument 404 /404.php
Hope this helps
Is it possible to have the log of the rewrite engine ?
Add the following lines in your configuration (bellow the RewriteEngine On is enough) :
RewriteLog logs/rewrite_https.log
RewriteLogLevel 15
I suppose your others logs are in logs/