I have a WP instance, and I see that any time I write a URL that has any string that contains 'moz' it errors out with a 404.
I have taken a look at my .htaccess looking for 'moz' and I see this:
RewriteCond %{REQUEST_URI} !^/moz(.*)
Why would that be causing a 404?
EDIT: The context of this RewriteCond
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/knowledge/
RewriteCond %{REQUEST_URI} !^/midphase(.*)
RewriteCond %{REQUEST_URI} !^/moz(.*)
RewriteCond %{REQUEST_URI} !^/Stats/(.*)
RewriteRule . /index.php [L]
It looks like someone added WordPress to a website with existing content. Those rewrite conditions check to see if the URL is for one of the existing folders, and if not, send the request to index.php.
That means of you enter a URL that starts with moz and points to a file that doesn't exist, you'll get a 404.
Related
for the last hours I cant seem to figure out why my .htaccess file is redirecting to a blank url. Here is my htaccess file below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-l
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ /test/user-profile/%1? [R=301,L]
I am trying to rewrite www.example/test/user-profile?id=4 ->>> www.example/test/user-profile/4
It does rewrite the url, however then the page has "The requested URL was not found on this server." the htaccess file is in public_html folder, so I am trying to select a specific user inside www.exampleurl.com/test/userslist.php which would go to www.exampleurl.com/test/user-profile.php. It all works perfectly before using htaccess. www.example/test/user-profile?id=4 ->>> www.example/test/user-profile/4 but it just wont find the url or file? im a super noob folder path below -> public_html/test/userslist.php & user-profile.php
Just cant seem to figure out what to do. Yes I do have mod-rewrite on.
With your shown samples, please try following htaccess rules file.
This assumes that you are hitting link www.example/test/user-profile?id=4 in browser which is redirecting to www.example/test/user-profile/4 and is being served by index.php with parameters user-profile=user-profile in your url and id=digits in url. You can also change them as per your need.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteBase /test/
RewriteCond %{THE_REQUEST} \s/(test/user-profile)\?id=(\d+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*/)/([*/]*)/?$ test/user-profile.php?user-profile=$1&id=$2 [QSA,L]
2nd solution: In case someone is hitting url example.com/test/user-profile/7 then try following htaccess rules.
RewriteEngine On
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*/)/([^/]*)/(\d+)/?$ test/user-profile.php?user-profile=$1&id=$2 [QSA,L]
I am trying to make an internal redirect (without changing the url in the client-browser) from "example.com/about" to "example.com?p=about".
I added the the folowing code to my .htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} !\?
RewriteRule ([^\/]*)$ http://%{HTTP_HOST}?p=$1 [L]
But if I open the page (example.com/about), I am getting an internal server error
Does anyone know what I am doing wrong?
Thanks for helping
Edit: If I add the R flag to the RewriteRule, everything works fine
You got error because your rule just add query string then capture again any URI even passed through this rule before so,Your rules should look like this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ http://%{HTTP_HOST}?p=$1 [L]
And to be more specific and able to handle real wrong requests by any other rule , do this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !p=(.*)
RewriteRule ^([^/]*)$ http://%{HTTP_HOST}?p=$1 [L]
This is my folder structure
htdocs
-> testing
->index.php
->.htaccess
Inside index.php I have this code
<?php
if(isset($_SERVER['PATH_INFO'])) {
echo $_SERVER['PATH_INFO'];
}
?>
Inside .htaccess I have this code
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [NC,L]
Here is my question:
In the above htaccess rewrite rule, which will link my address localhost/testing/HelloWorld to localhost/testing/index.php/HelloWorld
Is it possible to do some thing like this? When the user enter localhost/testing/index.php/HelloWorld I want the browser to hide the word index.php and only display something like this localhost/testing/HelloWorld
I tried to redirect the link localhost/testing/index.php/HelloWorld to localhost/testing/HelloWorld by adding another rule in .htacces file but I get "The webpage has redirect loop" error message.
After I add in new rule the .htacces file looks like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php/(.+)$ /testing/$1 [R]
Does any ways that I could make my link like this? Thanks in advanced, your help will be very much appreciated.
You get the redirect loop, because the rewritten url matches the rule for redirection. You'll need to use a trick to make the external redirect only happen on an external request with index.php, not on an internal rewrite that maps a different request to that file. You can do this with %{THE_REQUEST} which will only ever be whatever the external request was. It will not update if you rewrite the file it maps to.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /testing/index\.php/
RewriteRule ^index.php/(.+)$ /testing/$1 [R]
I currently have a blog setup as the subfolder of the main site, mydomain.com.au/blog/, however the /blog is dynamically generated through PHP and doesn't physically exist.
I have created a subdomain blog.mydomain.com.au and I am trying to get it to display everything just like mydomain.com.au/blog/ but mask the url so that it shows blog.mydomain.com.au.
I have made several attempts using htaccess and got close a couple of times, but there's always something wrong. Below are the 2 attempts which got me the closest to the expected results:
1st attempt
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com\.au$
RewriteRule ^.*$ http://www.mydomain.com.au/blog%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
This will get blog.mydomain.com.au to redirect to www.mydomain.com.au/blog/, but does not mask the URL (the address bar will show www.mydomain.com.au/blog/).
2nd attempt
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com\.au$ [NC]
RewriteRule blog/(.*) http://blog.mydomain.com.au/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
This got me the closest. It redirects and masks the URL just the way I want it to for all pages under /blog/ (e.g. blog.mydomain.com.au/whatever/ redirects to www.mydomain.com.au/blog/whatever/ but masks the URL as blog.mydomain.com.au/whatever/), but it doesn't do it for blog.mydomain.com.au, which gets redirected to www.mydomain.com.au.
You have two different requirements here. The first one is a rewrite, which will work, if the request is blog.mydomain.com.au and you remove the domain part and the R flag in the rule substitution
RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com\.au$ [NC]
RewriteRule !^blog/ /blog%{REQUEST_URI} [L]
The second one is an actual redirect, if the request is www.mydomain.com.au/blog/
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com\.au$ [NC]
RewriteRule blog/(.*) http://blog.mydomain.com.au/$1 [R,L]
When everything works as you expect, you can change R to R=301.
Never test with 301 enabled, see this answer
Tips for debugging .htaccess rewrite rules
for details.
Im working on a server with the following htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php
RewriteRule ^[^/]*\.html$ index.php
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/ - [L]
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/.*$ - [L]
Now they asked me to prepare a static page inside their server, lets call it http://www.myserver.com/mystaticpage.html
The problem is that when i try to access that url, it redirects to index.php. How could I alter the htacces file to address this problem without messing anything with the installed CMS?
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond ${REQUEST_URI} !^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)
RewriteRule .* index.php
The rules you used before were redundant: if .* is rewritten to index.php then why also rewrite ^[^/]*\.html$ index.php to it? it already matched previous rule...
They also overlapped - since the three RewriteCond conditions were only applied on the first rule. So the second rule was also applied to static files on disk.
Also, the two rules that were listed last had no effect whatsoever. Either you needed to list them first, or not at all. I converted them to an additional RewriteCond since they were only attempted to avoid rewrite on certain uris