i have a url www.example.com/mybooks/list.php?id=novel-15 now i want to rewrite this url as www.example.com/mybooks/novel-15 for this i have the following code in .htaccess file
<Files ~ "\.log$">
Order allow,deny
Deny from all
</Files>
RewriteEngine on
RewriteRule ^mybooks/([A-Za-z0-9-]+)/?$ mybooks/list.php?id=?id=$1 [NC,L]
but this is not working. anybody give me a good solution...
Try this rule in your /mybooks/.htaccess:
RewriteEngine on
RewriteBase /mybooks/
RewriteCond %{THE_REQUEST} /list\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ list.php?id=$1 [L,QSA]
Related
All attempts failed... I want http://olex-design.at/journal to to be redirected to http://olex-design.at/journal/alle through .htaccess.
So far I have the following - non working - rule in place which produces a 403 forbidden page.
RewriteRule ^journal/$ /journal/alle [R=301,L]
The .htaccess file is placed in the root directory. Maybe someone can point me towards the right direction...
All rules in .htaccess files:
Options -Indexes -MultiViews
RewriteEngine on
#Force non-www:
RewriteCond %{HTTP_HOST} ^www\.olex-design\.at [NC]
RewriteRule ^(.*)$ http://olex-design.at/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L]
RewriteRule ^journal/$ /journal/alle [R=301,L]
ErrorDocument 404 /404
With the support of my webhost I was able to resolve my issues described above. This is the complete code in my .htaccess file.
Please note that the first 4 lines did the trick. The code below is responsible to remove the "www", remove the "index" when your in home (http://olex-design.at) and remove the .html file extension.
RewriteOptions inherit
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^journal\/?$ "http\:\/\/olex\-design\.at\/journal\/alle" [R=301,L]
AddDefaultCharset utf-8
Options -Indexes -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.olex-design\.at [NC]
RewriteRule ^(.*)$ http://olex-design.at/$1 [L,R=301]
<IfModule mod_rewrite.c>
#index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/
RewriteRule ^index\.html$ http://olex-design.at/ [R=301,L]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
I'm trying to redirect from /somedir/index.php?action=something&id=x to /index.php?action=something&id=x
Only if action = something. id is dynamic.
Most recently I've tried this with no luck. What is wrong with this?
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (^|&)action=something($|&)
RewriteCond %{QUERY_STRING} (^|&)id=($|&)
RewriteRule ^somedir/index\.php$ /index.php?action?something&id=%2$ [NC,R]
</IfModule>
Note: somedir has an index.php and this rule in its htaccess. Will that result in conflicts?
RewriteRule ^.*$ index.php [NC,L]
Try this rule instead of your rule in .htaccess
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (^|&)action=something($|&)
RewriteCond %{QUERY_STRING} (^|&)id=x($|&)
RewriteRule ^somedir/index\.php$ /index.php?action=something&id=x [L,R=301]
</IfModule>
The result will not conflict.
You can use:
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (?:^|&)(action|id)=([^&]+)&(?:.*&)?(action|id)=([^&]+)(?:$|&) [NC]
RewriteRule ^somedir/index\.php$ /index.php?%1=%2&%3=%4 [NC,L,R=301]
</IfModule>
I would like to use .htaccess to use subdomains on a website but have little to no experience with .htaccess. I have the following in my .htaccess file but it doesn't work:
Most of this I copied from other peoples suggestions. What I want is to enter Family.mysitehere.org and have it go to mysitehere.org/Family
Can anyone tell me what is wrong with this code? Many thanks in advance.
DirectoryIndex index.html index.htm index.php
AddHandler cgi-script .cgi .pl
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule wmail$ http://webmail.x7hosting.com [R,NC]
RewriteCond %{HTTP_HOST} \.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.mysitehere\.org(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^(.*) /%1/$1 [L]
ErrorDocument 404 /404missing.php
What I want is to enter Family.mysitehere.org and have it go to mysitehere.org/Family
Use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
#RewriteCond %{HTTP_HOST} ^(Family)\.(mysitehere\.org)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
I'm trying to deny access to couple of subdirectories (when using specific url) that are in www-root.
My goal is:
Make domain.com/subdir{1-3} to deny access.
Make subdir{1-3}.domain.com to point to %{DOCUMENT_ROOT}/subdir{1-3}. Already works.
I want to write rules to httpd.conf without having to use .htaccess files and use only one Directory section if possible.
Here's what I've tried:
<Directory "/var/www/subdir1">
<IfModule rewrite_module>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/subdir1 [NC]
RewriteRule ^.* - [F]
</IfModule>
</Directory>
But no go.
//E
Got it working, here's what I did:
<Directory />
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/subdir1/ [OR]
RewriteCond %{REQUEST_URI} ^/subdir2/ [OR]
RewriteCond %{REQUEST_URI} ^/subdir3/ [OR]
RewriteCond %{REQUEST_URI} ^/subdir4/
RewriteRule .* - [F]
</IfModule>
</Directory>
Is there anything I should change to make it more safe?
Everything works except subdir3 which points to ownclouds root dir. It must have something to do with ownclouds own rewrite rules:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^.well-known/host-meta.json /public.php?service=host-meta-json [QSA,L]
RewriteRule ^.well-known/carddav /remote.php/carddav/ [R]
RewriteRule ^.well-known/caldav /remote.php/caldav/ [R]
RewriteRule ^apps/calendar/caldav.php remote.php/caldav/ [QSA,L]
RewriteRule ^apps/contacts/carddav.php remote.php/carddav/ [QSA,L]
RewriteRule ^apps/([^/]*)/(.*\.(css|php))$ index.php?app=$1&getfile=$2 [QSA,L]
RewriteRule ^remote/(.*) remote.php [QSA,L]
</IfModule>
Tips are welcome.
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^subdir1 - [L,F]
RewriteCond %{HTTP_HOST} ^subdir1\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subdir1/
RewriteRule ^(.*)$ /subdir1/$1 [L]
for "subdir1".
I am running a dokuwiki under http://blabla.com/ and now I have the additional url http://wiki.com/
What I want is to redirect users who request http://blabla.com/test/gna or anything else to http://wiki.com/test/gna without harmin the default .htaccess of dokuwiki
<Files ~ "^([\._]ht|README$|VERSION$|COPYING$)">
Order allow,deny
Deny from all
Satisfy All
</Files>
RewriteEngine on
RewriteBase /dev/
RewriteRule ^_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L]
RewriteRule ^_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L]
RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_$1&id=$2 [QSA,L]
RewriteRule ^$ doku.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) doku.php?id=$1 [QSA,L]
RewriteRule ^index.php$ doku.php
Just adding something like this at the end or beginning does not have any effect at all:
Rewritecond %{HTTP_HOST} !blabla.com/
RewriteRule ^/(.*)$ http://wiki.com/$1 [L,R=301]
Try using the below lines:
# Any URL from blabla.com will be redirected to corresponding URL on wiki.com
Rewritecond %{HTTP_HOST} ^blabla.com$
RewriteRule ^(.*)$ http://wiki.com/$1 [L,R=301]
Try removing the leading slash, apache removes it when passing URI's through rewrite rules in htaccess files:
Rewritecond %{HTTP_HOST} blabla.com
RewriteRule ^(.*)$ http://wiki.com/$1 [L,R=301]
Though you probably want to add it above your other rules so the redirected target doesn't have the doku.php?id=stuff in the URL.