I got an problem with url rewriteing. First of all i am starting to think that i am making mistake in the structure of my webpage. I made more than one php file. I think that this is mistake because in all tutorials and samples urls they are using in .htaccess only index.php.
Info 1. I got in navigation tab index.php section1.php section2.php section3.php section4.php 2. In index.php i only have an basic information that won't change much. 3. In each section.php file i am echoing out list of articles. 4. each aricle got id and i am using it to echo out information when user clicks on article link. 5. link to article " http://www.example.com/section1.php?id=607575 " 6. In each section.php file i got more than one page. 7. For now my links to section page looks like this " http://www.example.com/section1.php?page=1 ". Questions
Qestions
<a href="http://www.example.com/section1.php?page=1>section1</a>
do i need to manually rewrite them OR it dose not matter, .htaccess will do the job? if i need to rewrite url will it looks like this? <a href="http://www.example.com/section1.php/section1/page/1">section1</a>
How to rewrite urls so they look like this www.example.com/section1/page/1 and www.example.com/section1/article/607575 (i know it's bad to use only numbers, i just need to understand how it works,then i will figure it out,how to replace it with article name).
If I understand correctly, this is how you would rewrite:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /path/to/section1.php?page=$ [QSA,L]
I'm not very used to mod_rewrite but that should work. You might have to rewrite rule for ?article too.
If this was not answered correctly, please refer to http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
From: http://www.example.com/section1/page/1
To: http://www.example.com/section1.php?page=1
RewriteRule ^section(\\d+)/page/(\\d+)$ /path/to/section$1.php?page=$2
From: http://www.example.com/section1/article/607575
To: http://www.example.com/section1.php?id=607575
RewriteRule ^section(\\d+)/article/(\\d+)$ /path/to/section$1.php?id=$2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.