I'm using a custom built CMS and I need to rewrite the urls because currently they take the page ID and name of the page into the url.
/pages/1411760825/Facilities is an example of the current url
/Facilities is what I want it to show up as in the URL bar
The pages are linking to each other based on their ids and titles and I want it to not do that anymore.
This is the current .htaccess rule
RewriteEngine on
RewriteRule (.*)\.xml(.*) $1.php$2 [nocase]
I know I need to add a line below to rewrite what I want it to be, but I'm unsure how to achieve this.
Related
I am using laravel 5.2 and I have search form which pass GET parameter, so in url its like
http://www.example.com/list/item?&qs=&unit-type=Office&min-bed=&max-bed=&min-price=&max-price=
so search result is shown with such ugly url, I want to make this url seo friendly, I don't want to use post method.
Is there any .htaccess code that can help to make seo friendly url of such get parameter.
I tried this .htaccess code but doesn't work.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA]
What you are doing is possible, but shouldn't be done.
The page is not a static page, or a product page, or a listing page. It is a search result page.
The search result page should not be SEO friendly in terms of the url containing information about the search query because this is supposed to be dynamic. A search engine will not be interested in indexing a specific user's search result page on your website. A search engine will be interested in indexing the search page.
If you are looking to have a product listing page for example with pre-defined search queries, then why not just create a specific controller and for the time being, manually write an SEO friendly url to point to the required method on that controller?
e.g.
Route::get('offices-between-10000-and-20000-pounds', 'ListingController#getOfficesBetweenPriceRange');
I am creating my menu dynamically from a database. I started by appending an id to the urls which I used to identify the page in the database and then get all urls from the subpages and so on..
so I had a lot of ids like this www.page.com/somefolder/pagename.php?id=10, where 10 is the id of the page and is the parent_id for a number of other pages.
Now I use mod rewrite to get nicer urls. So the above url is now www.page.com/pagename.php , which is mapped to the original url.
My pagenames are all gonna be unique.
The question: Do I have to do this for each and every url, since each url needs an id as query string or is there a better way to combine mod rewrite with dynamically generating a menu?
No, not for every URL, but you will need to do this the other way around.
Turn the rewrite engine on
RewriteEngine on
Build a path to match against using a dynamic 'case' in brackets..
RewriteRule ^/?somefolder/page/([0-9]+)/?$
.. complete the rule with the rewritten URL, using $1 for the 'case'
/somefolder/pagename.php?id=$1 [L]
Put it all together using [L] to signify the 'last' rule to execute.
RewriteRule ^/?somefolder/page/([0-9]+)/?$ /somefolder/pagename.php?id=$1 [NC,L]
This will rewrite /somefolder/page/12345/ to /somefolder/pagename.php?id=12345
I have little knowledge of .htaccess file and able to rewrite url. but for huge number of pages and page specific url requirements, i can't define this in .htaccess file. I had to use database for storing different urls of different pages, now i don't have any idea how to use it. I know working of dynamic url rewriting also like rewriting following url
www.mysite.com/garments/news.php?id=32
to
www.mysite.com/garments/news/32
but what about random page urls like
www.mysite.com/garments/news.php
to
www.mysite.com/latest-news
To get this link i would use this:
RewriteEngine On
RewriteRule ^latest-news/([0-9]+)/?$ garments/news.php?id=$1
What this does is redirect this url:
www.mysite.com/latest-news/30/
to this:
www.mysite.com/garments/news.php?id=30
Is there a way to redierct a url to a php file based on one part of the url.
For example I have a url -
http://www.website.org/Cat/89/Diamond-Wedding-Rings.htm
I will have a few different of these urls. I wish to redirect all the pages with /Cat/ to a php file which will pull the Id and display the category and products.
in my htaccess I have
RewriteRule ^Cat/([0-9]+)/(.*)\.htm category.php?cat_id=$1&title=$2 [NC,L]
I'm not getting a 404 because the cms system redirects to the homepage if the page is not found.
I'm a complete noob when it comes to htaccess and I'm basing this on some of the existing rules in the htaccess which do something similar. I don't really need the title part it's really just the ID.
If all you need is the id then this will work
RewriteRule ^Cat/([0-9]+)/(.*) category.php?cat_id=$1
I have a MySQL database with 5000 items. The table is structured as
id
product-name
content
product-url
You can access a specific product page by going to www.site.com/products/index.php?id=123. The index.php file uses PHP to GET the ID to search the MySQL database and return the appropriate product name and content.
How can I make it so instead of www.site.com/products/index.php?id=123, the URL is rewritten or redirected to www.site.com/products/product-url? If I do it with .htaccess, will the index.php file still be able to know what ID to use to look up the product-url if the ID is not in the URL? Or is there some way to map URLs with PHP and MySQL?
(I'm a noob when it comes to this stuff, so any help will be much appreciated. Thanks.)
You can use .htaccess and a RewriteRule. The following will redirect an SEO URL to index.php with $_GET['product-url']. You will need to modify your code to either lookup the product id or use the product-url directly. Both should be unique in your products table.
RewriteEngine On
RewriteBase /
# redirect product page from SEO URL
RewriteRule ^products/([\w\d-_]+)/?$ products/index.php?product-url=$1 [L]
Note: I've made the product_url to only allow letters, numbers, dashes and underscores. I suggest such a restriction. In addition, the trailing slash is optional. Futhermore, this will not reappend a query string. If you need that you can add the QSA flag to the RewriteRule.