=> This is my folder structure
There is a file present name deploy_email.php
This is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
RewriteCond %{THE_REQUEST} ^[A-Z](3,)\s([^.]+)\.php [NC]
RewriteRule ^%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?/] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]
</IfModule>
The problem is i want the deploy_email.php file to be access with extension and rest of the file extensions should be hidden.
If i use the above .htaccess code while inspecting, i found that the data is not get by deploy_mail.php as you can see here => This here
Please provide some solution.
POST data gets lost while doing external redirection using R flag. You should skip all POST requests from redirect rule not just one file.
Replace all of your shown code with this:
RewriteEngine on
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
# redirect only all requests except POST
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.(?:php|html?)[\s?/] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
RewriteCond %{REQUEST_FILENAME}.htm -f
RewriteRule ^(.+?)/?$ $1.htm [L]
Clear your browser cache and retest.
Related
I would like to do a redirection through the htaccess :
Old URL :
http://www.website.com/?p=5729
New URL :
http://www.website.com/jmsblog/notrevie/18_charlie-raconte-les-chaussettes-qui-puent.html
So I do this in htaccess :
redirect 301 /?p=5729 http://www.website.com/jmsblog/notrevie/18_charlie-raconte-les-chaussettes-qui-puent.html
But it doesn't work, probably because of special character.
Someone as an idea?
***** EDIT ***********
Here is the htaccess file :
# ~~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: www.charlieetjune.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/x-font-woff .woff
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|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
RewriteCond %{THE_REQUEST} /\?p=5729
RewriteRule ^$ http://www.charlieetjune.com/jmsblog/notrevie/18_charlie-raconte-les-chaussettes-qui-puent.html? [L,R]
You can not Redirect Querystring using Redirect directive. You need to use the following Rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} /\?p=5729
RewriteRule ^$ http://example.com/path/? [L,R]
Don't forget to include the ? at the end of the destination url as it removes the old querystring.
I have a weird issue with my css files.
After i changed the htaccess file to this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} /eventDetails\.php\?id=([0-9]+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [L,R]
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
</IfModule>
my css files stoped loading to ALL the pages of the website.
My public_html folder contains
index.php
profile.php
css -> style.css
js -> owl.carousel.js
.htaccess
With Google Chrome Developer Tools i have this error for the css files
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://something.gr/css/style.css".
and this error for the javascript files
owl.carousel.js:1 Uncaught SyntaxError: Unexpected token <
Some images from the Network Tab.
WITHOUT .htaccess file
As you can see the Content-Type is text/css .. like it should be
WITH .htaccess file
As you can see here the mime.type returns it as a text/html
What i've tried.
First. after <title> html tag i've enternet
<base href="/">
Second. I've tried to change the .htaccess file to this
<IfModule mod_rewrite.c>
RewriteEngine on
AddType application/javascript js
AddType text/css css
RewriteCond %{THE_REQUEST} /eventDetails\.php\?id=([0-9]+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [L,R]
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
</IfModule>
And lastly i've checked on my dedicated server usr/local/apache/conf/
on the mime.types file that the text/css css is NOT commented the same as
application/javascript js
I dont know what else i should do.
Your second rule
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
rewrites /css/style.css to /eventDetails.php?id=css&name=style.css.
If you want to exclude existing files from this rule, you may prefix it with
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
You may also change the first rule to
RewriteCond %{QUERY_STRING} id=([0-9]+)&name=(.+)
RewriteRule ^eventDetails\.php$ /%1/%2? [L,R]
and to prevent a redirect loop we insert at the beginning
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
You don't need this of course, if you keep the existing condition and rule against THE_REQUEST.
So the complete rules become
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{QUERY_STRING} id=([0-9]+)&name=(.+)
RewriteRule ^eventDetails\.php$ /%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
i wrote a framework using clean url with this structure /fa/site/controller/method/id.the problem is ckfinder integrated with ckeditor in upload and browse pictures use another type of url. i want to exclude these addresses fron rewiting may help to work.
my htaccess codes is
AddType text/css .css
<Files "*.js">
ForceType text/javascript
</Files>
RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} ^/public/admin/plugins/ckfinder/ckfinder.html
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^.*$ index.php [NC,L]
#RewriteCond %{REQUEST_URI} !^/public/admin/plugins/ckfinder/1$ [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
i am using wamp v. 2.4.17
comments are my tries to help the story but not helped.
any help is appreciated
So I have:
-A mod_rewrite rule for a few things, including remove www., force https, and SEO
-A directory called stage that I want these rules to not apply to
Obviously as I'm posting here, the condition isn't being applied or met, and I have no idea why :(
A warning, I manually and automatically (using cPanel) manage my .htaccess, so it's pretty messy and I apologize sincerely in advance. I'd be very grateful if anyone could point out redundancy (I think I may see one but I'm unsure).
I appreciate any help anyone can offer me, even tips and not answers! I'm a beginner (relatively) and a software engineering student, so anything helps :) It may also explain my newbiness.
Here's my .htaccess file for the root public_html directory:
Thanks in advance :)
suPHP_ConfigPath /home/patters1/public_html
#AddType text/css .css
Options -Indexes
ExpiresActive On
ExpiresDefault "access plus 1 month"
# WEEK
<FilesMatch "\.(js|css|swf)$">
Header set Cache-Control "public, max-age=604800"
</FilesMatch>
RewriteEngine On
RewriteCond %{REQUEST_URI} !/selfcontrol
RewriteCond %{REQUEST_URI} !/myadmin
RewriteCond %{REQUEST_URI} !/stage
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)$ index.php?a=$1
RewriteCond %{REQUEST_URI} !/selfcontrol
RewriteCond %{REQUEST_URI} !/stage
RewriteCond %{REQUEST_URI} !/myadmin
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?a=$1
RewriteCond %{HTTP_HOST} ^www\.pattersoncode\.ca$
RewriteRule ^/?$ "https\:\/\/pattersoncode\.ca\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^!.pattersoncode\.ca$
RewriteRule ^/?$ "https\:\/\/pattersoncode\.ca\/" [R=301,L]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteCond %{HTTP_HOST} !^pattersoncode\.ca$
RewriteRule ^/?$ "https\:\/\/pattersoncode\.ca\/" [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://pattersoncode.ca/$1 [R=301,L]
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
ErrorDocument 404 /resources/error.php?a=das
ErrorDocument 401 /resources/error.php?a=4sdfdsc
ErrorDocument 403 /resources/error.php?a=4fsd
ErrorDocument 500 /resources/error.php?a=500fdf
ErrorDocument 400 /resources/error.php?a=400dsf
I would recommend to check your .htaccess file with this tool by commenting all your lines and uncommenting it one rule at a time. There are many errors / typo / duplicate lines in your code.
Here are a few errors:
Here is a duplicated rule:
RewriteCond %{REQUEST_URI} !/selfcontrol
RewriteCond %{REQUEST_URI} !/myadmin
RewriteCond %{REQUEST_URI} !/stage
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)$ index.php?a=$1
RewriteCond %{REQUEST_URI} !/selfcontrol
RewriteCond %{REQUEST_URI} !/stage
RewriteCond %{REQUEST_URI} !/myadmin
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)$ index.php?a=$1
Here you wrote this but I think that you meant !^pattersoncode\.ca$:
RewriteCond %{HTTP_HOST} ^!.pattersoncode\.ca$
And you could have combine it with the previous condition
RewriteCond %{HTTP_HOST} ^www\.pattersoncode\.ca$ [OR]
RewriteCond %{HTTP_HOST} ^!.pattersoncode\.ca$
Why this rule should only work on port 80 contrary to the previous ones ?
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://pattersoncode.ca/$1 [R=301,L]
You should remove the " characters from this rule
RewriteRule ^/?$ "https\:\/\/pattersoncode\.ca\/" [R=301,L]
I dont really know too much about Rewrite in apache, but there is problem with my .htaccess file.
the original .htaccess is
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_.]*)$ /profile.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Unless directory, remove trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.domain.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.domain.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
ErrorDocument 404 /404.html
The first rewrite is for vanity url, another is redirecting non www to www and after that .php to extension less and redirecting .php file to extension less,
Problem i am facing is, if i request www.domain.com/ttt.php and if ttt doesn't exist then it redirects me to http://www.domain.com/profile?id=ttt.php
Also, i want the rewrite to be for php files not other type, Say if i have ttt.png file and i open www.domain.com/ttt it opens the image rather than showing 404 error.
Similarly happens with other type of files. It opens .txt file first if the names are common.
Thanks for any changes to this, seriously i don't want to mess my site.
This rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_.]*)$ /profile.php?id=$1 [L]
Needs to be at the very end.
And this rule:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Needs the [L] flag and needs to replace RewriteRule ^([^/.]+)$ $1.php [L]. Then you can duplicate this one and replace .php with .png, and .txt and every other extension you want to handle, in the order of preference:
Options +FollowSymLinks -Multiviews
RewriteEngine on
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Unless directory, remove trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.domain.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.domain.com/$1 [R=301,L]
# add extension if the php file exists:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
# add extension if the png file exists:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.png -f
RewriteRule ^(.*)$ $1.png [L]
# add extension if the txt file exists:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.txt -f
RewriteRule ^(.*)$ $1.txt [L]
# add extension if the html file exists:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
# etc.
# finally, route to profile.php if all else fails
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_.]*)$ /profile.php?id=$1 [L]
ErrorDocument 404 /404.html
Since you're routing to profile.php, in the profile.php script, you'll need to redirect to /404.html if the id param doesn't exist (meaning the URI that got routed needs to be a 404).