is there a way to replace an url with the .htaccess like this:
http://website.com/file.php?watch=video
to this one:
http://website.com/file/watch/video
Tried with this,and haven't worked.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/watch/([\d]+)$ $1.php?watch=$2 [L]
My .htaccess file:
#remove php file extension-e.g. https://example.com/file.php will become
https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/watch/([\w-]+)$ $1.php?watch=$2 [L]
Have it this way:
RewriteEngine on
RewriteBase /test/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /([\w-]+)\.php\?watch=([^\s&]+)\s [NC]
RewriteRule ^ %1/watch/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/watch/([\w-]+)$ $1.php?watch=$2 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
I have a issue with Frog CMS, its the first time I use this CMS, is a client that uses this.
Scenario: I modified 1 redirection using a plugin called "Redirector" that destroyed the whole site!
Luckly, I found an htaccess from some months ago, that allows the site to work, but the redirections none of them works, the site works, but not the redirections, the main url rewriting for the site seems to be Ok, but the 301 redirects I need, dont work.
I cant figure out why this is happening, why this redirections dont work correctly, they dont conflict, but they dont do nothing! Can you advice on this ? Im looking forward uderstanding more about url rewritting and htaccess.
I cant use the plugin to generate redirections, because it destroyed the whole site. If there is a way to "reset" the url rewritting in this CMS it would be good, but I dont have cooperation form the developers of the site...
I appreciate any help to understand better what is wrong , why all the
RewriteRule ^site/services/immigration/ /services/immigration.html [L,R=301]
dont work!
### CMS-Generated Update August 1, 2013, 1:45 pm ###
#
# Setting Frog requirements
#
AddType text/x-component .htc
AddType video/ogg .ogm
AddType video/ogg .ogv
AddType video/ogg .ogg
AddType video/webm .webm
AddType video/mp4 .mp4
AddType video/x-m4v .m4v
AddType audio/webm .weba
AddDefaultCharset UTF-8
Options -Indexes -MultiViews +FollowSymLinks
DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !.local$ [NC]
RewriteCond %{HTTP_HOST} !.local$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^install/index.html$ install/index.php?rewrite=1 [L,QSA]
RewriteRule ^install/index.php$ install/index.php?rewrite=1 [L,QSA]
RewriteRule ^install/$ install/index.php?rewrite=1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^admin(.*)$ admin/index.php?$1 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^$ /cache/index.html [L,QSA]
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /cache/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^download/(.*)$ /downloads.php?THISPAGE=download.html&media=pdf&filename=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^private/(.*)$ /private.html?THISPAGE=private.html&userfile=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^mobile/search/(.*)$ mobile.html?THISPAGE=search.html&media=mobile&search=$1 [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^mobile/(.*)/process.html$ mobile.html?THISPAGE=$1&media=mobile&return=process [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^mobile/(.*)/success.html$ mobile.html?THISPAGE=$1&media=mobile&return=success [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^standard/search/(.*)$ standard.html?THISPAGE=search.html&media=standard&search=$1 [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^standard/(.*)/process.html$ standard.html?THISPAGE=$1&media=standard&return=process [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^standard/(.*)/success.html$ standard.html?THISPAGE=$1&media=standard&return=success [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^(.*)/process.html$ contact.html?THISPAGE=$1&return=process [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/success.html$ contact.html?THISPAGE=$1&return=success [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^search/(.*)$ index.php?THISPAGE=search.html&search=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^proposal.html$ index.php?THISPAGE=$1&media=proposal [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^contrast/search/(.*)$ contrast.html?THISPAGE=search.html&search=$1&media=contrast [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^print/search/(.*)$ print.html?THISPAGE=search.html&search=$1&media=print [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^mobile/(.*)$ mobile.html?THISPAGE=$1&media=mobile [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^standard/(.*)$ standard.html?THISPAGE=$1&media=standard [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^print/(.*)$ print.html?THISPAGE=$1&media=print [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^pdf/(.*)$ pdf.html?THISPAGE=$1&media=pdf [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^proposal/(.*)$ proposal.html?THISPAGE=$1&media=proposal [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^flash/(.*)$ flash.html?THISPAGE=$1&media=flash [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^contrast/(.*)$ contrast.html?THISPAGE=$1&media=contrast [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?THISPAGE=$1 [L,QSA]
RewriteRule ^/site/aboutus/(.*)$ /$1 [L,R=301]
RewriteRule ^site/aboutus/ / [L,R=301]
RewriteRule ^pages/about_us.htm /about.html [L,R=301]
RewriteRule ^site/contact/ /contact.html [L,R=301]
RewriteRule ^site/library/ /resources.html [L,R=301]
RewriteRule ^site/services/ /services.html [L,R=301]
RewriteRule ^site/services/alternative_dispute_resolution/ /services/alternative-dispute-resolution.html [L,R=301]
RewriteRule ^site/services/business_visas/ /services/business-visas.html [L,R=301]
RewriteRule ^site/services/civil_comm_litigation/ /services/civil-commercial-litigation-copy.html [L,R=301]
RewriteRule ^site/services/clinical_negligence/ /services/clinical-negligence.html [L,R=301]
RewriteRule ^site/services/conveyancing/commercial/ /services/commercial-conveyancing.html [L,R=301]
RewriteRule ^site/services/company_law/ /services/company-law.html [L,R=301]
RewriteRule ^site/services/criminal_law/ /services/criminal-law.html [L,R=301]
RewriteRule ^site/services/divorce_matrimonial/ /services/divorce-matrimonial.html [L,R=301]
RewriteRule ^site/services/employment_law/ /services/employment-law.html [L,R=301]
RewriteRule ^site/services/human_rights/ /services/human-rights-issues.html [L,R=301]
RewriteRule ^site/services/immigration/ /services/immigration.html [L,R=301]
RewriteRule ^site/services/leases_tenancy/ /services/leases-tenancy-agreements.html [L,R=301]
RewriteRule ^site/services/injury_medical_negligence/ /services/personal-injury-medical-negligence.html [L,R=301]
RewriteRule ^site/services/pro_bono/ /services/pro-bono.html [L,R=301]
RewriteRule ^site/services/conveyancing/ /services/residential-conveyancing.html [L,R=301]
RewriteRule ^site/services/conveyancing/residential/ /services/residential-conveyancing.html [L,R=301]
RewriteRule ^site/services/wills_trusts_probates/ /services/wills-trusts-probates.html [L,R=301]
RewriteRule ^site/people/ /team.html [L,R=301]
</IfModule>
It's because you have this rule before all of your other services redirect rules:
RewriteRule ^site/services/ /services.html [L,R=301]
This is saying, "anything that starts with /site/services/ gets redirected to /services.html". So, when you have a rule like:
RewriteRule ^site/services/company_law/ /services/company-law.html [L,R=301]
after it, the second rule will never get executed, since the second rule matches /site/services/company_law, which starts with /site/services/, thus matching the first rule. You need to re-order all of your rules so that the more general rule is at the end. Just put the
RewriteRule ^site/services/ /services.html [L,R=301]
rule at the very bottom.
I can't figure out how to rewrite this URL
http://localhost/site/page.php?id=[pagetitle]
to
http://localhost/site/page/title
and
for user profiles
http://localhost/site/profile.php?username=username
to
http://localhost/site/profile/username
This is the code I'm using:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile(.*)$ profile.php?username=$1
RewriteRule ^(.*)$ page.php?title=$1
this will rewrite the input localhost/site/page/title to loacalhost/site/page.php?id=[pagetitle]
RewriteRule ^localhost/site/(.+)$ site/page.php?id=$1
RewriteRule ^localhost/site/profile/(.+)$ site/profile.php?username=$1
This should work
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/(.*)$ profile.php?username=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/(.*)$ page.php?title=$1
assumed that the .htaccess at the /site/ directory
I only got the first pretty url working. I don't get the 2nd and 3rd working, they just show a messed up page (Styles not loaded) + it show wrong page
Here is my code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?tab=$1 [NC]
RewriteRule ^/ucp(.*)$ index.php?ucp&tab=$1 [NC]
RewriteRule ^/ucp(.*)$ index.php?ucp [NC,L]
.
Possible urls:
http://subdomain.domain.com/path2files/index.php?&tab=str
http://subdomain.domain.com/path2files/index.php?ucp
http://subdomain.domain.com/path2files/index.php?ucp&tab=str
How they should look like:
http://subdomain.domain.com/path2files/str
http://subdomain.domain.com/path2files/ucp
http://subdomain.domain.com/path2files/ucp/str
Try this:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /path2files/index\.php\?ucp&tab=(.*)\ HTTP
RewriteRule ^ /path2files/ucp/%2\? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^path2files/ucp/(.*)$ /path2files/index.php?ucp&tab=$1 [L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /path2files/index\.php\?ucp\ HTTP
RewriteRule ^ /path2files/ucp\? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^path2files/ucp$ /path2files/index.php?ucp [L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /path2files/index\.php\?&tab=(.*)\ HTTP
RewriteRule ^ /path2files/%2\? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/ucp
RewriteRule ^path2files/(.*)$ /path2files/index.php?&tab=$1 [L]
I'm trying to create redirect to different files for different subdomains, maybe domains in the future. This is based on ModX CMS.
I want to keep url the same, just run different file for each subdomain, passing some data. For domain.com it's index.php, for sub1.domain.com - sub1.php. Also I want to pass some data, you can see it in the example below:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub1\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub1.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub2\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub2.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub3\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub3.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub4\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub4.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub5\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub5.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub6\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub6.php?q=$1 [L,QSA]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I tried to # last 3 lines, but it didnt make any difference. I've got more lines in htaccess, but they are #. Subdomain I create in control panel of my server, all subdomains are ponted to the same directory (public_html).
Right now I'm not sure passing data works, and when I go to sub1.domain.com apache redirect me to www.domain.com/sub1.php, thich is wrong.
How do I link subdomains to their php files and keep url the same (sub1.domain.com)??
Remove redundant stuff and keep your code like this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub1\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub1.php?q=$1 [L,QSA]