hello I am facing a problem with my htacess i have two php files that are used for URL rewriting first one is video.php and second one is channel.php. on homepage when I click any video its properly works for rewriting the url e.g.
mysite.com/video.php?url=1234
changes to that works properly for me
mysite.com/1234-video-custom-slug
but when I click for any channel it loads the same video.php but with rewriting urls of channel like:
mysite.com/channel/1-channel-slug
instead of rewriting urls from channel.php?id=1
I don't know what i am doing wrong here is my htaccess file code
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+)$ video.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ video.php?url=$1
RewriteRule ^channel/([a-zA-Z0-9-/]+)$ channel.php?id=$1
RewriteRule ^channel/([a-zA-Z0-9-/]+)/$ channel.php?id=$1
Change the order like this
RewriteEngine On
RewriteRule ^channel/([a-zA-Z0-9-/]+)$ channel.php?id=$1
RewriteRule ^channel/([a-zA-Z0-9-/]+)/$ channel.php?id=$1
RewriteRule ^([a-zA-Z0-9-/]+)$ video.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ video.php?url=$1
Related
I am trying to get my htaccess to rewrite the url to display two folders rather than two vars.
Here is my url:
www.MyWebsite.com/index.php?p=info&id=1234
That is actual url but I want it to display this:
www.MyWebsite.com/info/1234
Here is the code for the htaccess but it does not work for the second var.
DirectoryIndex index_good.html index.php
RewriteEngine On
RewriteBase /tjshow/
# RewriteRule ^([\w\-]+)/*$ ?p=$1 [L]
# RewriteRule ^([\w\-]+)/([\w\-]+)/*$ ?p=$1&id=$2 [L]
RewriteRule ^([\w\-]+)/*$ index.php?p=$1 [L]
RewriteRule ^([\w\-]+)/([\w\-]+)/*$ index.php?p=$1&id=$2 [L]
RewriteRule ^([\w\-]+)/([\w\-]+)/([\w\-]+)/*$ index.php?p=$1&id=$2&link=$3 [L]
The first one works fine but the second one is giving me a page but with all kinds of internal broken links and images.
This one works:
www.MyWebsite.com/index.php?p=info
And it displays this only, which is what I want it to do:
www.MyWebsite.com/info
But if I add the second var there like this
http://mywebsite.com/tjshow/second
Then the code breaks.
Try using this rule instead:
RewriteRule ^([^/]*)/([^/]*)$ /index.php?p=$1&id=$2 [L]
Using the above rule will leave you with the URL: www.MyWebsite.com/info/1234
I've made some search about .htaccess Rewrite function, but I couldn't find any example with an html reference.
I'm trying to redirect from my example.com/products/category/ link to another page.
Here's the link what I'd like the .htaccess file to redirect:
<a href="example.com/products/category/?category=bathroom">
I'd like to achieve this style:
example.com/products/category/bathroom/
Here's my .htaccess ReWriteRule:
RewriteRule ^products/([A-Za-z0-9-]+)/?$ /products/category.php/?category=$1 [L] # Process category
Note that I'm using two different php pages for both. page-category.php and category.php
I've places it after
RewriteEngine On
RewriteBase /
but still it doesn't work.. The only time something happened when I tried some combinations, it threw back an internal server error. Is there a problem with my RegEx or am I not doing the linking right ?
EDIT: I'm using wordpress, I forgot to mention that, sorry.
You need to use Redirect 301
RedirectMatch 301 ^example.com/products/category/?category= /example/home/page-category.php
Or you can use mod_rewrite instead:
RewriteEngine On
RewriteRule ^example/products/category/?category= /example/home/page-category.php [L,R=301]
same you can do for another file.
as i understood from your question you need something like this in category directory .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) category.php?category=$1 [QSA]
Now anything that is not a directory or a file inside category directory will be rewriten like /category/bathroom will be rewriten to (without redirection) /category.php?category=bathroom
I have a question regarding the .htaccess file.
I have rewritten a dynamic url in a static one as following:
www.mysite.com/index.php?lang=IT
in
www.mysite.com/it
using this rewrite rule:
RewriteEngine On
RewriteRule ^it/([^/]*)\.html$ /index.php?lang=$1 [L]
So far so good...
Now I need to create another static url for a dynamic url which redirects to the product description
www.mysite.com/product_details.php?id=1485
The rule inserted in the .htaccess is:
RewriteEngine On
RewriteRule ^it/prodotto-([^-]*)-([^-]*)\.html$ /it/product_details.php?id=$1&lang=$2 [L]
Unfortunately if I click on the related link I cannot reach the requested page; but if I comment the first rule like this
#RewriteRule ^it/([^/]*)\.html$ /index.php?lang=$1 [L]
then I can see the page.
Do you know how to solve this issue?
Assuming that lang equals to language you want the script do like so?
RewriteEngine On
RewriteBase /
RewriteRule ^it/([^/]*).html$ /index.php?lang=$1 [L]
RewriteRule ^it/prodotto-([^/]*)-([^/]*).html$ /it/product_details.php?id=$1&lang=$2 [L]
this will do
yoursite.com/it/$1.html
and
yoursite.com/it/prodotto-$1-$2.html
?
I need to rewrite only 1 specific URL, to display to visitors specific content: I tried something like, this:
RewriteEngine on
RewriteCond %{REQUEST_URI} example.com/test/2_5/page.html
RewriteRule ^(.*)$ example.com/tt.html [R,L]
I need to rewrite all requests to:
http://example.com/test/2_5/page.html
to
http://example.com/tt.html
how to do this?
thanks,
Redirect /test/2_5/page.html /tt.html
Ok, mod_rewrite
RewriteRule ^/test/2_5/page.html /tt.html [L]
Remove first / if using .htaccess in the site's root folder, not the .conf file. And, typically, the final url should be the full one, with http:// and domain, but this one will work too. If you want to do everything by the rules then
RewriteRule ^/test/2_5/page\.html$ http://example.com/tt.html [L]
I have a page on my website that dynamically displays content. The URL structure is mywebsite.com/giveaway/giveaway.php?id=(any number)
I wish to change that dynamic URL into a static/friendly URL mywebsite.com/giveaway/name-of-giveaway-corresponding-to-id.
In my .htaccess file found in my root folder i have the following:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+\?page=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [R=301,L]
# existing rule
RewriteRule ^page/([^/]+)/?$ /?page=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [L]
The current .htaccess file removes .php and also redirects and changes a URL on my site from
mywebsite.com?page=number to mywebsite.com/page/number
I know you have to get the name corresponding to the ID in php from my database and use that, but im not sure how to write the code in the .htaccess file or how to use and pass the results from the database. Thanks for any help!
I don't know if that is what you mean, but you can't connect the rewrite engine, which is part of the underlying Apache server layer, to the database, which has to be accessed by php.
So you can't rewrite the "name-of-giveaway-corresponding-to-id" to the id directly, you need to rewrite it to something like giveaway.php?nameofgiveaway=(name of giveaway) and then search the database for that string.
Your way to go is to add a rewrite rule like
RewriteRule ^giveaway/([^/]+)$ giveaway.php?nameofgiveaway=$1 [L,QSA]
(not tested, so forgive me if something is wrong) and search for $_GET['nameofgiveaway'].