htaccess的和不断变化的PHP查询到一个干净的网址干净、网址、htaccess、PHP

2023-09-02 01:01:44 作者:烽火戏诸侯只为驳伊人一笑

我试图更改URL结构,为我的客户的网站,我从来没有与一个htaccess文件之前,所以请原谅我,如果它是一个愚蠢的问题。我花时间寻找在堆栈溢出,谷歌和YouTube,但对我的生活中,我只是不能让我的头,围绕这一点。

该网址目前的结构: JOBTITLE作为变量和管理 - 乔布斯是值

 的http://localhost/website/job_title.php JOBTITLE =管理,职位
 

的URL结构的客户端已请求

 的http://本地主机/网站/管理,职位
 

htaccess的文件我已经尝试:

  RewriteEngine叙述上
重写规则^ jobs_by_title.php /([0-9A-ZA-Z_-])job_title.php?JOBTITLE = $ 1
 
PHP中的.htaccess伪静态文件

也有一次,我有这个HT访问文件的工作,应该需要在PHP脚本去干净的版本而不是脏吗?或者这会自动在htaccess的呢?

编辑:

我有,现在有工作

  ^([A-ZA-Z0-9 _-] +)?$ job_title.php?JOBTITLE = $ 1 [L]
 

解决方案

您正则表达式,用于捕获URI是错误的。

将这个$ C $在C /website/.htaccess

  RewriteEngine叙述上
的RewriteBase /网站/

的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^([^ /] +)/ $ job_title.php?JOBTITLE = $ 1 [L,QSA]
 

I am trying to change the URL structure for my clients website, i have never worked with a htaccess file before so forgive me if its a stupid question. i have spent time looking on stack overflow, google and youtube but for the life of me i just cant get my head around this.

The URL Current structure: jobtitle being the variable and Administration-Jobs being the value

http://localhost/website/job_title.php?jobtitle=Administration-Jobs    

the URL structure the client has requested

http://localhost/website/Administration-Jobs

The htaccess file i have attempted:

RewriteEngine On
RewriteRule ^jobs_by_title.php/([0-9a-zA-Z_-]) job_title.php?jobtitle=$1    

also once i have this ht access file working, what should be required in the php script to go to the clean version rather then the dirty one? or is this done automatically in the htaccess?

EDIT:

I have got it working now with

^([A-Za-z0-9_-]+)?$ job_title.php?jobtitle=$1 [L]    

解决方案

Your regex for capturing URI is wrong.

Place this code in /website/.htaccess:

RewriteEngine On
RewriteBase /website/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ job_title.php?jobtitle=$1 [L,QSA]