I develop an e-shop site with products so for this proposal i made a product page for each of products with Mod_Rewrite for URL with the code above in my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ ./product.php?name=$1 [L]
So when user clicks on the link www.example.com/Nike-Air goes to Nike-Air shoes page and etc.
What i would like to do is to add one parameter more in the url, let's say size
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ ./product.php?name=$1&size=$2 [L]
but this parameter to not append in the url, still to displays www.example.com/Nike-Air
and also to be able to get the size data from $_GET method.
Is it possible?
Any ideas guys?
Related
I have a website that has lots of pages, and i want to rewrite url for all the pages without page name,
for example:
http://example.com?category.php?cat_name=mobile
It should become like this.
http://example.com/mumbai/mobile
dubai will be a dynamic value which will keep changed by php.
We have another one the same like this.
http://example.com?blog.php?blog_name=restaurants
http://example.com/delhi/restaurants
I have lots of pages like these mentioned above but url should hold the value of city name and page name should not be there.. Blog page will redirect to blog page and category will redirect to category page only.
I did try like this.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ category.php?cat_name=$1 [QSA,NC,L]
But it didnt work because all redirections will only hit to the first url category.php and the same page only.
How can I get the second part of a url to be a variable, rewrite it, and provide a fancy URL.
So example www.mywebsite.com/AFL would rewrite to www.mywebsite.com/index.php?league=AFL but would still display as www.mywebsite.com/AFL.
I am using the same pages for multiple leagues. When a user signs up they establish a league name in the database and then on each page I look for the league variable to display the info.
I also have many different pages. So a user could go to www.mywebsite/AFL/schedule_teamdisplay.php?Team=ABC&Year=2014. This would rewrite to www.mywebsite.com/schedule_teamdisplay.php?league=ALF&Team=ABC&Year=2014.
The league will always be the second entry in the URL.
Thanks
You can put this code in your htaccess (which has to be in your root folder)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /index.php?league=$1 [L]
RewriteCond %{DOCUMENT_ROOT}/$2 -f
RewriteRule ^([^/]+)/([^/]+)$ /$2?league=$1 [L,QSA]
My present url structure :
domain.com/items/view/5
domain.com/user/view/5
domain.com/user/edit/5
Now i don't want users to directly know the 'id' in the url, as they can directly fire a query from the address bar.
Hence i want to mask the url to :
domain.com
i.e. domain.com/anything will come as it is but the url will not change.
Thanks in advance.
Also note that i have already made .htaccess file with following code to remove 'index.php' from the url and that is working perfect.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
Can't be done. The only way to hide the id is to pass it outside the url - i.e. as POST data; but .htaccess doesn't have access to that, only the url.
Your code should instead handle the fact that users could enter the url directly and either act correctly or use a http-redirect header to send the user back to the main page.
I have WordPress site that has films and actor custom post types. Also I'm creating relationship with films and actors.
I have a page to list films that related to actor. On this page visitors can see in which films actor take role.
This pages URL is like this:
http://www.mywebpage.com/actors-films/?id=123456
id refers to the actor, with this id I'm doing a query and showing it on the page.
also this page supports pagination, this URL works too:
http://www.mywebpage.com/actors-films/page/2/?id=123456
actors-film page is a page that uses a custom template, this template determines the actor id and shows his films.
Every thing works fine, but I want to change the URL a little bit SEO friendly.
I have tried many URL formats
http://www.mywebpage.com/actors-films/jim-carrey
I don't know why but this URL redirects to actors page.
http://www.mywebpage.com/actors/jim-carrey
http://www.mywebpage.com/actors-films/123456-jim-carrey
I have tried to catch this kind of URL with .htaccess but no way to catch it, it always shows a 404 not found.
So, I need to do a rewrite with pagination support, can you please suggest me a way to do this?
edit : here is my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^actors-films/([0-9]*)\-([^/]*)$ ^actors-films/?id=$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Edit : I have realized that not rules works for me :
example :
http://www.mywebsite.com/tex shows a 404 with this rule : RewriteRule ^/tex /index.php [L]
Here is the solution, create a page named
add_filter('query_vars', 'ap_register_query_vars');
function ap_url_redirect_rules(){
add_rewrite_rule('actors-films/([^/]*)','index.php?pagename=artist-film-list&actor_slug=$matches[1]','top');
flush_rewrite_rules();
}
function ap_register_query_vars($query_vars){
$query_vars[]='actor_slug';
return $query_vars;
}
Now we can call the url http://mywebsite.com/actors-films/john-doe
i have script in index.php in ALL folders
need to make pretty url/seo friendly urls like this: site.com/folder1/something.html
now i have ugly urls like this: site.com/folder1/index.php?category=something
this part index.php?category=something is always the same in all subfolders, i just want to change it to more seo friendly like something.html
once again: find index.php?category=1$ and replace it with 1$.html
do not touch anything else, just this part of url
so when i visit:
site.com/another-subfolder/and-one-more-folder-here/index.php?category=something
need to see this in address bar:
site.com/another-subfolder/and-one-more-folder-here/something.html
i hope you get it?
i tried this with folder1 in htaccess in root
RewriteRule ^folder1/(.*).html$ folder1/index.php?category=$1 [L,R=301]
ok this works, but how can i make this to work for all subfolders accross the site like this:
site.com/folder145/index.php?category=something
site.com/subfolder/index.php?category=something
site.com/another-subfolder/and-one-more-folder-here/index.php?category=something
there will be 1000s of subfolders with different names so manually making RewriteRule for each subfolder won't work
any help is appreciated
First, you need to change all the links that you generate from the index.php?category= form to the category.html form.
Then in the htaccess file in your document root, you add these rules to internally rewrite the category.html form back to the index.php?category= form:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?/)?([^/]+)\.html$ /$1index.php?category=$2 [L]
Then, to point links you don't have any control over (or ones generated using a FORM) externally redirect any direct access to links in the index.php?category= form:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ (/.*?)?/index\.php\?category=([^&\ ]+)
RewriteRule ^(.+?/)?index\.php$ /$1%3.html? [L,R=301]
This should match any and every subdirectory.