I looked at this: htaccess remove index.php from url but it didn't work and in the comments there seems to be disagreement on the top answer.
If I type in http://www.example.com/thanksgiving/index.php/getThankyou I get the page I want served.
If I type in http://www.example.com/thanksgiving/getThankyou I get a 404.
What I've tried in my htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/thanksgiving/(.*)/$ /thanksgiving/index.php/$1 [L]
</IfModule>
How do I do it so /thanksgiving/getThankyou/ or any url starting with /thanksgiving in the url leads to the proper resource being served? Again, it is currently available when index.php is in the url.
I also tried: RewriteRule ^/thanksgiving/[^/]*/$ /thanksgiving/index.php/$1 [L] but that didn't work either...
Edit: It seemed part of the htaccess is being set by wordpress and may be conflicting with the desired behavior above:
The wordpress part of the same htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Is this interfering? How do I reconcile this with the /thanksgiving/ urls which are not part of the Wordpress application?
Edit:
The above only pertains to the root (public_html) htaccess, below is the htaccess in /thanksgiving/ itself, please analyze for conflicts, thanks for all your help!
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
# Do not change this line.
# Change example.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change your_app_name to the subfolder name
RewriteCond %{REQUEST_URI} !^/thanksgiving/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change your_app_name to the subfolder name
# Change example.com to your domain name
RewriteRule ^(.*)$ /thanksgiving/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ thanksgiving/index.php [L]
You need to remove the leading slash from your rewrite pattern :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:thanksgiving/)?(.*)$ /thanksgiving/index.php/$1 [L]
</IfModule>
Otherwise the rule will accept the uri starting with a double leding slash (ie : //thanksgiving/ ) .
Related
I need to let an external software collect a zip file from my Wordpress site. The site is converted to https, but the software asks for the HTTP version of the file, http://www.example.com/foldername/grunfil.zip
So can I add something in .htaccess to make that file only http?
Here is my current .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I tried this, but it creates an endless loop:
redirect 301 /foldername/grunfil.zip http://www.example.com/foldername/grunfil.zip
Check this rule, maybe it help.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^foldername\/grunfil\.zip
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I followed this instruction to protect subdirectory.
https://support.hostgator.com/articles/wordpress-preventing-you-from-password-protecting-a-directory
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Changed to
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]
</IfModule>
# END WordPress
It can protect sub-directory in Wordpress without returning to 404 page but It seems that the website link is not valid.
Example. Website returns error page is it does not have slash at the end of domain.
Working domain: http://demodomain.com/something/
Not working domain: http://demodomain.com/something
try the following optionsrule just below RewriteEngine On:
1) RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]
2) #Removing trailing slash
RewriteRule ^(.*)/$ /$1 [L,R]
Add slash at the end of URL
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
Or Do Following
# Ensure all URLs have a trailing slash.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
I need to set up the http://domain.com/wp1/ to be shown like http://domain.com/
I have tried to set up any rewrite in the past hours, but no success :(
P.S. There is a wordpress installed in the public_html/wp1, configured to work on http://domain.com/wp1/ URL. Its .htaccess is as follows:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp1/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp1/index.php [L]
</IfModule>
# END WordPress
Thanks in tons!
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain-name.com$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /folder/$1 [L]
Changing the document root for the domain does the job.
I switched my website to wordpress but now url link end with slash(/) instead of .html and i don't wanted to lose my google index so After banging my head around here and there , I have finally found a solution. i created .htaccess rule that will work globally for every page.
I just updated the .htaccess file in root with below code:
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]
Now any URL like this: /features/cart/ will automatically forward to /features/cart.html
Everything was working fine but now i am getting 404 error on those page which already have .html extension.
Please advice asap, because i am loosing my indexing and keyword ranking.
Here below is the actual code of .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
# Rewrite rule for appending .html
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]
redirect 301 /about_us.html /about.html
redirect 301 /about/ /about.html
</IfModule>
# END WordPress
Site name: dailydealbuilder.com
Try reordering your rules:
Redirect 301 /about_us.html /about.html
Redirect 301 /about/ /about.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
# Rewrite rule for appending .html
RewriteRule ^(.+?)/$ $1.html [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)\.html$ index.php/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
I have a pretty standard WordPress .htaccess with the following URL rewrites
# 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
WordPress is installed in my domain root. I have some other scripts in subfolders, e.g. /opencart These subfolders contain their own .htaccess files.
Unfortunately, it seems that WordPress hijacks the rewrites for some of these scripts sometimes.
How can I ask mod_rewrite to ignore WordPress rules for rewrites when encountered with specific subfolders e.g. opencart and to use the rules defined in the .htaccess within these subfolders instead?
You may try replacing the complete WP rule-set with this one:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(folder1|folder2|folder3) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
In the .htaccess file in your site root, add the following ABOVE the WordPress .htaccess directives:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^/(folder1)/(.*) /folder1/$2 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,R]
</IfModule>
# END WordPress