http://www.example.com/blog/demo/first-post
http://www.example.com/blog/test/second-post
I would like to rewrite the above url to
http://www.example.com/first-post
http://www.example.com/second-post
I used:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /demo/$1 [L]
But it doesn't work for test. Please help.
Related
Is it possible to using htaccess?
I want to keep my original url "menu", but also use /en/menu/ for it.
Here is my code so far (sorry I am terrible at htaccess):
RewriteEngine On
RewriteBase /server/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/menu/ [NC]
RewriteRule ^([^/]+)/([^/]+)en/menu/ [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /menu/ [L,QSA]
I'm totally newbie in htaccess and it has been a month since I'm trying to rewrite this one URL but no luck. Tried searching on the internet a lot and tried out the method that worked for others but not working for me unfortunately.
The htaccess rule for my dynamic page works, for example site/index.php?viewpage=application shows up as site/application
What I'm struggling to do is, I'm trying to rewrite the following url: site/application?name=abcd&date1-2-3&version=5.0 to site/application/abcd/1-2-3/5.0
This is my htaccess code
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?viewpage=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /application?name=$1&date=$2&version=$3 [L]
Try this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !name
RewriteRule ^([^/]+)$ index.php?viewpage=$1 [L]
RewriteRule ^(.+)/(.+)/(.+)/(.+)$ /$1?name=$2&date$3&version=$4 [L]
If you want the last line to be limited with application only , replace with this :
RewriteRule ^application/(.+)/(.+)/(.+)$ /application?name=$1&date$2&version=$3 [L]
UPDATE CODE:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !name
RewriteRule ^([^/]+)$ index.php?viewpage=$1 [L]
RewriteRule ^(.+)/(.+)/(.+)/(.+)$ index.php?viewpage=$1?name=$2&date$3&version=$4 [L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ index.php?id=$1 [L,QSA]
the above i have in my htacces file which rewrites directory/page to index.php?id=directory/page
thats working fine.
I also want to be able to add the following to it:
domain.com/sections/page rewrites to index.php?section=1&id=page
domain.com/sections/page2 rewrites to index.php?section=1&id=page2
domain.com/page rewrites to index.php?id=page
the ID is going to be different for each page
You have to take a look at RewriteCond and RewriteRule directives.
That's a sample .htaccess based on your edit.
RewriteEngine On
# This will process the /sections/(.*) requests, ?section=1 will be appended to query string
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^sections\/(.*)?$ index.php?section=1&id=$1 [L,QSA]
# This will process the other requests, as it does now.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ index.php?id=$1 [L,QSA]
I want to change page url with .htaccess my url is 'page.com/web/' and I want to have just page.com. Could you give me htacces code. for example
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?$1 [L]
Try this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ web/$1 [NC,L]
My all URLs formats are like these:
http://example.com/category?format=feed
http://example.com/category/sub_category/?format=feed
for example: http://example.com/computer/cpu/?format=feed
Is there a way via htaccess to change top URLs to these:
http://example.com/category/feed
http://example.com/category/sub_category/feed
example1: http://example.com/computer/cpu/feed
example2: http://example.com/computer/feed
These rules should meet both requirements. But allows you to change the category and subcat as long as the normal URLs don't change and format is always a key in the query string.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/(.+)/(.+)$ /$1/$2/?format=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/(.+)$ /$1/?format=$2 [L]
Then you should be able to use these URL types.
http://example.com/category/feed
http://example.com/category/sub_category/feed
The following should achieve what you are looking for:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^format=(.*)$
RewriteRule ^(.*)/(.*)/$ /$1/$2/%1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^format=(.*)$
RewriteRule ^(.*)$ /$1/%1? [L,R]
The above will turn:
http://example.com/category?format=feed to http://example.com/category/feed
and
http://example.com/category/sub_category/?format=feed to http://example.com/category/sub_category/feed