I've been working on my htaccess file to allow rewritten URL paths and everything works fine on my Localhost but when I upload it to the server and type in the url I get a 404 saying:
The requested URL /** was not found on this server. Additionally,
a 404 Not Found error was encountered while trying to use an
ErrorDocument to handle the request.
I've tried to ask my hosting account support team but they say they can't help with this type of problem. My htaccess code is:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^issue=(.*?)&edition=(.*?)&id=(.*?)&title=(.*?)$
RewriteRule ^article.php$ /article/%1/%2/%3/%4 [L,R]
And an example url is:
http://mywebsite.co.uk/article/1/leeds/1394216062/jupiter-falls-to-tour-with-syron-vanes-and-rdc
Why am I getting the 404 & how can I sort this?
You seem to have written the reverse rule. Try this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^article/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /article.php?issue=$1&edition=$2&id=$3&title=$4 [L,QSA,NC]
This will handle: /article/1/leeds/1394216062/jupiter-falls-to-tour-with-syron-vanes-and-rdc URLs.
Related
I am trying to redirect people, that try to access a specific folder on web to receive 404
Example: if anyone wants to access www.mysite/myfolder/ I wish that person to receive 404 error
What I have tried by now:
RewriteCond %{REQUEST_URI} ^/node/$
RewriteRule .* - [F]
RedirectMatch 301 www.yoursite/node/
RewriteEngine on
RewriteRule ^//node/123 /node/999 /node/128173/(.*)$ /pages/errors/404.php$1 [R=301,L]
None of those really worked-received 500 error
Also tried to simply redirect everything to a non-existent site, like this:
Options +FollowSymLinks
RewriteEngine On
Redirect 301 /node/*.* http://www.your imaginary site/to-new-url
Yet, still received 500
Can anyone please help?
Why not deny access to /node/ folder?
<Directory /node/>
Deny from all
</Directory>
or modify your rewrites in .htaccess to:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^node/ [NC]
RewriteRule (.*) /pages/errors/404.php [R=301,L]
But it's not good practice, 404 page should return HTTP 404 status not HTTP 301 as redirect.
Hi all and thank you for answering
my 500 error was apparently due to not specifying https in the redirect form
After that everything worked
I'm using a php app called Yourls. It's a self-hosted url shortener and it's pretty great, I'm happy with its overall functionality. Due to the nature of its development however there isn't much in the way of support. Let's pretend the base url is af.to, where a shortened url would be af.to/goo that might redirect to whatever url is defined by 'goo'. The problem I'm facing is that if someone goes to af.to, they end up on a 403-Forbidden. I'd rather the client is redirected to a specific url instead. I have already picked up a plugin for Yourls which redirects to a url when a shortlink is not found or mis-typed, but this does not cover the base of af.to
I attempted to put in a 403 redirect in the .htaccess, but that broke the whole yourls script resulting in a 500 server error.
Current .htaccess looks like this:
# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>
# END YOURLS
Any help on what I need to do?
Thank you.
The RewriteCond blocks tell the RewriteRule to skip existing files / folders. When you go to http://af.to/, the root folder exists : no redirection. The apache server doesn't find any index.html (or index.php) file, isn't allowed to list the content of the folder, give up and returns a 403 Forbidden.
You can create the index.html file to show some content or you can add these lines to redirect to an other url :
# just after RewriteEngine On
RewriteRule ^/$ http://my-compagny.com/ [L,R=301]
I am using .htaccess for url redirect. I have tried lot of things but it is giving me "NOT FOUND" ERROR
My current Url is
http://localhost:8089/travell/search.html?/india/goa
I need the url to be
http://localhost:8089/vacation/india/goa
My htaccess file is having
RewriteRule ^(.*)?search.html http://localhost:8089/vacation?%{Query_string} [P]
You're doing reverse in your rule. Use this rule in root .htaccess:
RewriteEngine On
RewriteRule ^vacation/(.+)$ travell/search.html?$1 [L,NC,QSA]
Then test it by entering http://localhost:8089/vacation/india/goa in browser.
htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^dev/(.*)/$ /out.php?q=$1 [L]
RewriteRule ^dev/(.*)/([a-z]+)$ /out.php?q=$1&s=$2 [B,L]
URL request:
http://example.com/dev/100%25%20Booster%20Juice%20(6%20Hours)/supply
For some reason, the above request results in a server error while these:
http://example.com/dev/100%25%20Booster%20Juice%20(6%20Hours)/
http://example.com/dev/Energy%20Juice%20(6%20Hours)/supply
http://example.com/dev/Energy%20Juice%20(6%20Hours)/
work flawlessly and do not generate an error. I have no idea why it's just that one specific URL that doesn't work.
I'm working on a website where I want the url
www.example.com/directory1/states/california.php
to point to
www.example.com/directory1/california
And a similar url change for the city pages as well:
www.example.com/directory1/cities/miami.php
should point to
www.example.com/directory1/miami
I'm using the following rules in my access file to change the url:
RewriteRule ^directory1/(alabama|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|guam|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachusetts|michigan|minnesota|mississippi|missouri|montana|nationwide|nebraska|nevada|new_hampshire|new_jersey|new_mexico|new_york|north_carolina|north_dakota|ohio|oklahoma|oregon|pennsylvania|rhode_island|south_carolina|south_dakota|tennesee|texas|us_virgin_islands|utah|vermont|virginia|washington|west_virigina|wisconsin|wyoming)$ /directory1/states/$1.php [L]
RewriteRule ^directory1/(.*)$ /directory1/cities/$1.php [L]
However, nothing changes in the url bar and I always get a 404 not found. When I tested it with the htaccess checker, the output url is always correct. What is wrong with my rules? Is there a way to test how/if mod_rewrite is even functioning?
Some server configs require you to turn the rewrite engine on in your .htaccess file. Right at the top:
RewriteEngine on
I've also known some server configs where the file path starts/ends with a / (due to other rewrite rules already being run on the request) so perhaps allow for that to be there in the rules:
RewriteRule ^/?directory1/(alabama|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|guam|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachusetts|michigan|minnesota|mississippi|missouri|montana|nationwide|nebraska|nevada|new_hampshire|new_jersey|new_mexico|new_york|north_carolina|north_dakota|ohio|oklahoma|oregon|pennsylvania|rhode_island|south_carolina|south_dakota|tennesee|texas|us_virgin_islands|utah|vermont|virginia|washington|west_virigina|wisconsin|wyoming)/?$ /directory1/states/$1.php [L]
RewriteRule ^/?directory1/(.*)/?$ /directory1/cities/$1.php [L]