i want to make my URL become from this:
www.mysite.com/index.php?area=test1&par=test2
to this:
www.mysite.com/test1/test2
my .htaccess look like that:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*?)/?$ /index.php?area=$1 [L]
DirectoryIndex index.php
i get only the area variable, and dont know how to continue from here.
why not simply pass all to php like
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
than process it in php
var_dump($_SERVER);//parse all info you want
Related
Today i start with my mod rewrite for the php script.
Some words to the setup
I use a subdomain e.g. test.testsystem.com which points to root/test/
So i have some multiple GET Parameters for my PHP script like the following:
1) https://test.testsystem.com/index.php?a=foo
2) https://test.testsystem.com/index.php?a=foo&v=bar
3) https://test.testsystem.com/index.php?a=foo&c=testcode
so with mod rewrite i want to have
1) https://test.testsystem.com/foo
2) https://test.testsystem.com/foo/bar
3) https://test.testsystem.com/foo/c/testcode
What i currently have is
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /test/
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?a=$1 [QSA]
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?a=$1&v=$2 [QSA]
For the first two URLs. Now it does no error 500 any more but the problem is i do not get any GET parameters in my php script.
Maybe someone can provide me here a working solution.
Regards
Assuming your test.domain.com is pointing to the /test folder , you can use something like the following in your /test/.htaccess .
Options -Multiviews
RewriteEngine on
#1)Rewrite /foo to /index.php?a=foo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?a=$1 [L]
#2)rewrite /foo/bar to /index.php?a=foo&v=bar
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?a=$1&v=$2 [L]
#3)rewrite /foo/bar/buzz to /index.php?a=foo&v=bar&z=buzz
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?a=$1&v=$2&z=$3 [L]
The RewriteConds are important in each rules to avoid rewriting your existing files and directories .
I'm trying to rewrite a url that looks like http://example.com/View/(random_text) to take the user to http://example.com/View/site.php?site=(random_text)
This is what I am ussing so far:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^View/(.+)$ View/site.php?site=$1 [NC]
Any help is appreciated, thanks.
Try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/View/(.+)$ /View/site.php?site=$2 [L,R=301]
If the "View" directory is in your webserver's root directory, then add just the single forward slash as above. Else add the path to the view directory like below:
RewriteRule ^(.*)/View/(.+)$ /path_to_view_directory/View/site.php?site=$2 [L,R=301]
Lets say my site structure is like this:
www.mywebsite.com/directory/$variabledirectoryname/$variableproductlink
As you can see in the middle i have 2 variables in the url, but the last is the poduct link. My index.php file stays in www.mywebsite.com/directory/$variabledirectoryname folder. How to load it?
I have this code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ index.php [L]
But it doesnt work.. Thanks !
You can use this rule in /directory/.htaccess:
RewriteEngine On
RewriteBase /directory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/[^/]+/?$ $1/index.php [L]
Update:
You can use this rule in root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(directory/[^/]+)/[^/]+/?$ $1/index.php [L]
I am having a tough time to understand how mod_rewrite works.
I have a url like this:
www.example.com/store/index.php?categ=headbands
And I want to make it look like this:
www.example.com/store/headbands
I am trying this, but not working:
RewriteEngine on
RewriteBase /store/
RewriteRule ^index/([^/\.]+)/?$ $1 [L]
And I confirmed the mod_rewrite is activated with a random example I found.
Any suggestions?
Thanks!
Try This one
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/store/(.*)$ /store/index.php?categ=$1 [NC,L]
OR
Put the .htaccess file inside the "store" directory with following code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?categ=$1 [NC,L]
I currently have this set up and working fine inside a users folder.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?i=$1
e.g 127.0.0.1/site/users/admin goes to 127.0.0.1/site/users/index.php?i=admin
Now as this is for a profile page, how would i do something such as this.
users/admin/activity
So that it would show the activity page for that user? I am totally confused on how i would go about this.
Would it be best to make the index.php accept a page $_GET variable? But the how would i get htaccess to work around it?
You rules will look something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)$ index.php?i=$1&page=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?i=$1 [L]
Now your index.php should be getting 2 $_GET variables, i and page.