Rewriting to hide the querystring - .htaccess

I've been trying to create a page that can be accessed by passing a query string to check what version should be loaded. Instead of accessing the page by using www.domain.com?version=one I'd like to be able to use www.domain.com/one and the rule should turn /one into /version=one.
Is this possible?

Something like this should work.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /?version=$1 [L,QSA]

Related

htaccess for SEO friendly urls

So for two days I can not understand why this won't work...:
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^advice/([a-zA-Z]+)/([0-9]+)/$ advice.php?advice=$1&id=$2
Obviously .htaccess is allowed since I am not able to directory open folders, but why doesn't the link work?
Try turning off multiviews so the server doesn't try and search for that as a file. In addition add the conditions so that it knows it's not looking for a real file or directory it's trying to serve and make the trailing slash optional.
Options -Indexes +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^advice/([a-zA-Z]+)/([0-9]+)/?$ /advice.php?advice=$1&id=$2 [L]
Does your RewriteRule redirect to an existing file?
Try this, it works for me
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /test2/test.php
http://example.com/test2/.htaccess shows the location of the .htaccess file
http://example.com/test2/test.php is a direct link
http://example.com/test2/testX4XX opens the same test.php file using rewrite

.htaccess for php switch case

I am trying to make a friendly url for my website but when i use it, it always uses the current folder as rewrite and not show images, css,...
RewriteEngine On
RewriteOptions inherit
Options +FollowSymlinks
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^number/([a-z0-9]+)/?$ /index.php?id=read&num=$1 [L,NC]
and i have result as mydomain.com/number/123456/
but my page not showing with theme because all link js,css,images,... change in to /number/123456/
example: mydomain.com/number/123456/css/style.css or mydomain.com/number/123456/images/logo.png
But all that in root folder is mydomain.com/css and mydomain.com/images ~~!
How can i use with that format and my page can show correctly :(
Any solutions?
Please help me!

htaccess config : using part of the URL as parameter

I'm using a URL shortener and i'd like to have the following :
from http://domain.com/ld541as2 redirecting to http://www.newsite.com/login-ld541as2.html
There are a lot of possible URL but i'm guessing it's possible to do it with 1 rule ?
Any chance any of you guys know how to do so ?
Thanks for your help
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /login-$1.html [L,R]
PS: If you don't want full (external) redirection then remove R flag from above rule.

htaccess & mod_rewrite: display dynamic php page with a folder

I would want an adress like this:
http://www.domain.com/some_page123/
to display the content of this page:
http://www.domain.com/script.php?var=some_page123
But i want the URL that appears in the browser to be www.domain.com/some_page123/
Is it possible to do that with htaccess even if the folder "some_page123" doesn't really exist ?
Also, i want to exclude the folder named "infos" from this rewriting. So if an user access the URL www.domain.com/infos/ then it will display the content of "infos" folder. I do NOT want to use script.php rewriting for the folder "infos"
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (?!^infos/)^(.+?)/?$ /script.php?var=$1 [L,QSA,NC]
add .htacces in your root directory:
RewriteRule ^script.php - [L,NC]
RewriteRule ^infos/$ - [L,NC]
RewriteRule ^(.*)$ /script.php?var=$1
now I have tested it, it should be working.

rewriting urls with htaccess

What I need to do is change the links on my website, for example from
www.mywebsite.com/index.php
www.mywebsite.com/index.php?action=about_us
to
www.myswebsite.com/index.html
www.myswebsite.com/about_us.html
I was told htaccess was used to acheive this and I presume this is achieved with some sort of regular expression.
How can I achieve this result?
you have
www.mywebsite.com/index.php?action=about_us
and you want
www.myswebsite.com/about_us.html
in your .htaccess file add a line to the end of this file:
redirect /about_us http://www.myswebsite.com/about_us.html
voila
http://affiliate-minder.com/internetmarketing/using-htaccess-file-for-affiliate-link-redirects/
PK
Turn on the rewrite engine. The RewriteRule will fetch the page in the second parameter when the first parameter is called. So www.myswebsite.com/about_us.html will load www.mywebsite.com/index.php?action=about_us, but the URL in the address bar will still be www.myswebsite.com/about_us.html. The [NC] at the end just makes it case insensitive.
RewriteEngine On
RewriteRule ^/about_us\.html$ index.php?action=about_us [NC]
More info:
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html
CheckSpelling on
Options -Indexes
Options +FollowSymlinks
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$\.html /index.php?action=$1 [L,QSA]
and from there, you could use index.php to either navigate, or just display the content

Resources